package com.service;

import com.dao.userDao;

import java.sql.ResultSet;
import java.sql.SQLException;

public class userService {
    private userDao userDao=new userDao();



    public ResultSet checkUser(int userid,String password) throws SQLException, ClassNotFoundException {

        return userDao.checkUser(userid,password);
    }

    public boolean registerUser(int userid,String userName,String password,String address) throws SQLException, ClassNotFoundException {
        boolean isRegister = userDao.insertUser(userid, userName, password, address);
        return isRegister;
    }


    public boolean checkUserExist(int userid) throws SQLException, ClassNotFoundException {
        ResultSet resultSet = userDao.checkUserExist(userid);
        while(resultSet.next()) {
            if (resultSet.getString(1) == null||resultSet.getString(1).equals("")) {
                return false;
            } else {
                return true;
            }
        }
        return false;
      }

      //得到用户名
      public String getUserName(int userid) throws SQLException, ClassNotFoundException {
          ResultSet resultSet = userDao.checkUserExist(userid);
          String name="";
           while (resultSet.next()){
               name = resultSet.getString(2);
           }
          return name;
      }


      //得到用户余额
     public double getUserMoney(int userid) throws SQLException, ClassNotFoundException {
         ResultSet resultSet = userDao.checkUserExist(userid);
         double money=0.0;
         while (resultSet.next()){
             money=resultSet.getDouble(5);
         }
         return money;
     }


     public void decrUserMoney(int userid,double decrMoney) throws SQLException, ClassNotFoundException {
        userDao.decrUserMoney(userid,decrMoney);
     }






}
